package com.example.service;

import com.example.entity.Department;
import com.example.mapper.DepartmentMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentService {

    @Resource
    private DepartmentMapper DepartmentMapper;

    /**
     * 新增
     */
    public void add(Department Department) {
        DepartmentMapper.insert(Department);
    }

    /**
     * 删除
     */
    public void deleteById(Integer id) {
        DepartmentMapper.deleteById(id);
    }

    /**
     * 批量删除
     */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            DepartmentMapper.deleteById(id);
        }
    }

    /**
     * 修改
     */
    public void updateById(Department Department) {
        DepartmentMapper.updateById(Department);
    }

    /**
     * 根据ID查询
     */
    public Department selectById(Integer id) {
        return DepartmentMapper.selectById(id);
    }

    /**
     * 查询所有
     */
    public List<Department> selectAll(Department Department) {
        return DepartmentMapper.selectAll(Department);
    }

    /**
     * 分页查询
     */
    public PageInfo<Department> selectPage(Department Department, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Department> list = DepartmentMapper.selectAll(Department);
//        System.out.println("dwjqjop+++++"+list);
        return PageInfo.of(list);
    }


}
